package com.hqd.ch03.v12.io.support;


import com.hqd.ch03.v12.io.Resource;
import com.hqd.ch03.v12.io.ResourceLoader;
import com.hqd.ch03.v12.io.support.ClassPathResource;
import com.hqd.ch03.v12.io.support.FileSystemResource;

public class DefaultResourceLoader implements ResourceLoader {

    @Override
    public Resource getResource(String location) {
        if (location.startsWith(CLASSPATH_URL_PREFIX)) {
            return new ClassPathResource(location.replace(CLASSPATH_URL_PREFIX, ""));
        } else if (location.startsWith(FILE_URL_PREFIX)) {
            return new FileSystemResource(location.replace(FILE_URL_PREFIX, ""));
        }
        return null;
    }
}
